import { Component, OnInit, ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { JsonApiService } from "app/core/api/json-api.service";
import { config } from '../../shared/smartadmin.config';

declare var $: any;
@Component({
	selector: 'sa-langyun-data',
	templateUrl: './langyun-data.component.html',
	styleUrls: ['./langyun-data.component.css']
})
export class LangyunDataComponent implements OnInit {
	tableData:any[] = []; //table数据
	totalCount:number = 0; //分页总条数
	curPage:number = 1; //分页当前页
	pageSize:number = 10; //内置的分页每页条数
	startTime: string = '';//开始时间
	endTime: string = '';//结束时间
	searchKey: string = ''; //搜索keyword
	imgList:any = []; // 图片路径
	// 记录标志 0-删除1-正常2-作废
	signList:any =["删除","正常","作废"]
	constructor(private router: Router, private activatedRoute: ActivatedRoute, private jsonApiService: JsonApiService) {
		activatedRoute.queryParams.subscribe(queryParams => {
		});
	}

	ngOnInit() {
		this.load()
	}

	//刷新
    refresh(){
    	this.load();
	}
	// 分页回调
	paginate(e) {
		this.curPage = e.page + 1;
		this.pageSize = e.rows;
		this.load();
    }
	//查询
	tableSearch() {
		this.curPage = 1;
		this.load();
	}
	// 获取列表数据
    load() {
        let param = {
            "pageSize": this.pageSize,
            "nowPage": this.curPage,
            "parameters": {
                startTime: this.startTime,
                endTime: this.endTime,
                searchKey: common.stringTrim(this.searchKey),
            }
        }
        let reqdata = 'gridPager=' + JSON.stringify(param);
        this.jsonApiService.http("weighbridgeForLY/list.html", reqdata).subscribe(result => {
            let data = []
            if (result.isSuccess && result.exhibitDatas) {
				data = result.exhibitDatas
				for (let index = 0; index < data.length; index++) {
					const item = data[index];
					item.fsignText = this.signList[item.fsign]
				}
                this.tableData = result.exhibitDatas
                this.totalCount = result.recordCount;
            }
        });
    }
	//时间选中回调
	datePickerSelected(time){
		this.startTime = time.startTime;
		this.endTime = time.endTime;
	} 
	// 查看图片
	showImg(url,modal){
		modal.show();
		this.imgList = url;
	}
	closeImg(modal){
		modal.hide();
	}
}